#!/bin/bash

[ -z "${MYSQL_ROOT_PASSWORD}" ] && exit 1

ORIGINAL_PASSWORD=$1
#判断是否有密码输入
if [ -z "${ORIGINAL_PASSWORD}" ];
then
  echo "root_password.sh need password!"
  exit 1
fi

SQL_FILE=${APP_OUTPUT_DIR}/root_password_temp.sql
echo "set global validate_password_policy=0;" >> ${SQL_FILE}
echo "set global validate_password_length=1;" >> ${SQL_FILE}
echo "set password  = password('${MYSQL_ROOT_PASSWORD}');" >> ${SQL_FILE}
mysql -u root --password=${ORIGINAL_PASSWORD} --connect-expired-password < ${SQL_FILE}
! [ ${MYSQL_SAVE_SQL_TEMP} == YES ] && rm -rf ${SQL_FILE}